package com.creditease.mobile.util;

import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import android.util.Log;

/**
 *
 */
public class LruCacheUtil {
    private static final String TAG=LruCacheUtil.class.getName();
    private LruCacheUtil() {
    }

    //    private DiskLruCache mDiskCache;
    private static LruCache<String, Bitmap> mMemoryCache = new LruCache<String, Bitmap>(10 * 1024 * 1024) {
        @Override
        public int sizeOf(String key, Bitmap value) {
            return value.getRowBytes() * value.getHeight();
        }
    };

    public static void addBitmapToCache(String key, Bitmap bitmap) {

        if (key!=null &&bitmap!=null&& getBitmapFromMemCache(key) == null) {
            mMemoryCache.put(key, bitmap);

            Log.d(TAG,mMemoryCache.size()+"");

        }
    }

    public static Bitmap getBitmapFromMemCache(String key) {
        return mMemoryCache.get(key);
    }
}
